//
//  HomePageViewController.swift
//  maopu
//
//  Created by 黄海波 on 2017/4/12.
//  Copyright © 2017年 maopu. All rights reserved.
//

import UIKit

class HomePageViewController: BaseViewController{
    fileprivate var tableView:UITableView!

    override func viewDidLoad() {
        super.viewDidLoad()
        self.initView()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
    
    internal func initView(){
        self.navigationItem.title = "猫扑大杂烩"
        self.navigationItem.leftBarButtonItem = UIBarButtonItem.setImgBarButton(imgName: "searchBtn_ico", action: #selector(self.toSearchVCClick), target: self)
        self.navigationItem.rightBarButtonItem = UIBarButtonItem.setImgBarButton(imgName: "editButton_ico", action: #selector(self.toReleasePostsVCClick), target: self)
        
        self.tableView = UITableView.init(frame: CGRect.init(x: 0, y: 0, width: AppWidth, height: AppHeight), style:UITableViewStyle.grouped)
        self.tableView.estimatedRowHeight = 200
        self.tableView.rowHeight = UITableViewAutomaticDimension
        self.tableView.separatorStyle = .none
        self.tableView.keyboardDismissMode = .onDrag
        self.tableView.tableHeaderView = UIView.init(frame: CGRect.init(x: 0, y: 0, width: AppWidth, height: 0.01))
        self.tableView.delegate = self
        self.tableView.dataSource = self
        self.tableView.register(UINib(nibName: "HomePageListItemCell", bundle: nil), forCellReuseIdentifier: "cell")
        self.view.addSubview(self.tableView)
    }
    
    //MARK: 前往搜索页
    @objc fileprivate func toSearchVCClick(){
        let vc = SearchViewController()
        self.navigationController?.pushViewController(vc, animated: true)
    }
    //MARK: 前往发帖页
    @objc fileprivate func toReleasePostsVCClick(){
        let vc = ForumsChooseTypeController()
        let nv = BaseNavigationController.init(rootViewController: vc)
        self.present(nv, animated: true, completion: nil)
    }
    
}

extension HomePageViewController:UITableViewDelegate , UITableViewDataSource{
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 3
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! HomePageListItemCell
        cell.selectionStyle = .none
        cell.refreshCellData(cellType: 0)
        return cell
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let vc = HotchpotchReplyDetailVC()
        self.navigationController?.pushViewController(vc, animated: true)
    }
}
